<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>第七课 代理模式</title>
</head>
<body>
    <script>
        var computedFn = function(num){
            if(num <= 2){
                return 1;
            }else{
                return arguments.callee(num - 1) + arguments.callee(num - 2);
            }
        }

        var proxyNewFn = (fn,cache={}) => {
            return new Proxy(fn,{
                apply:function(target,context,args){
                    var argsString = args.join(',');
                    if(argsString in cache){
                        return cache[argsString];
                    }
                    return cache[argsString] = fn.apply(this,args);
                }
            });
        }
        var fn1 = proxyNewFn(computedFn);
        console.log(fn1(40));
        console.log(fn1(40));

    </script> 
</body>
</html>